package com.golddaymicromall.activity.recharge;


import android.graphics.Color;
import android.support.v4.app.Fragment;


import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.golddaymicromall.activity.R;
import com.golddaymicromall.adapter.RechargeAdapter;
import com.golddaymicromall.base.BaseActivity;
import com.golddaymicromall.fragment.HuiKuanDengJiFragment;
import com.golddaymicromall.fragment.ZaiXianHuiKuanFragment;

import java.util.ArrayList;
import java.util.List;

public class RechargeActivity extends BaseActivity implements ViewPager.OnPageChangeListener,View.OnClickListener {
    private FragmentManager fm;
    private ViewPager mVp;
    private RechargeAdapter adapter;
    List<Fragment> fragmentList = new ArrayList<Fragment>();
    private LinearLayout mReacharge_back;
    TextView mRecharge_DengJiTv;
    TextView mRecharge_HuiKuanTv;
    TextView Recharge_leftLine;
    TextView Recharge_rightLine;
    PopupWindow mPopWindow;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recharge);

        initView();
        initList();
    }

    private void initView() {
        mRecharge_DengJiTv= (TextView) findViewById(R.id.Recharge_DengJiTv);
        mRecharge_HuiKuanTv= (TextView) findViewById(R.id.Recharge_HuiKuanTv);
        Recharge_leftLine= (TextView) findViewById(R.id.Recharge_leftLine);
        Recharge_rightLine= (TextView) findViewById(R.id.Recharge_rightLine);
        mVp= (ViewPager) findViewById(R.id.RechargeActivity_VP);
        mReacharge_back = (LinearLayout) findViewById(R.id.recharge_back);
        mReacharge_back.setOnClickListener(this);
        mVp.setOnPageChangeListener(this);
        mRecharge_HuiKuanTv.setOnClickListener(new mVPListener(0));
        mRecharge_DengJiTv.setOnClickListener(new mVPListener(1));
    }

    private void initList() {
        fm= getSupportFragmentManager();;
        fragmentList.add(new ZaiXianHuiKuanFragment());
        fragmentList.add(new HuiKuanDengJiFragment());
        adapter = new RechargeAdapter(fm, fragmentList);
        mVp.setAdapter(adapter);
        mVp.setCurrentItem(0);
    }

    class mVPListener implements View.OnClickListener{
        private int index=0;

        public mVPListener(int i) {
            index =i;
        }
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            mVp.setCurrentItem(index);
        }
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        clearTvColor();
        switch(position) {
            case 0:
                mRecharge_HuiKuanTv.setTextColor(getResources().getColor(R.color.primary));
                Recharge_leftLine.setTextColor(getResources().getColor(R.color.primary));
                Recharge_leftLine.setVisibility(View.VISIBLE);
                Recharge_rightLine.setVisibility(View.INVISIBLE);
                break;
            case 1:
                mRecharge_DengJiTv.setTextColor(getResources().getColor(R.color.primary));
                Recharge_rightLine.setTextColor(getResources().getColor(R.color.primary));
                Recharge_rightLine.setVisibility(View.VISIBLE);
                Recharge_leftLine.setVisibility(View.INVISIBLE);
                break;
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
    //清理顶部导航textview文字颜色方法
    private void clearTvColor(){
        mRecharge_DengJiTv.setTextColor(Color.GRAY);
        mRecharge_HuiKuanTv.setTextColor(Color.GRAY);
        Recharge_leftLine.setTextColor(Color.GRAY);
        Recharge_rightLine.setTextColor(Color.GRAY);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.recharge_back:
                finish();
                break;
        }
    }
}
